using TMPro;
using UnityEngine;
using Voodoo.GameOps;
using Voodoo.Pattern;

public class DroneRVButton : MonoBehaviour
{
	public GameObject Root;

	public TextMeshProUGUI Text;

	public Item DroneItem;

	private bool _available;

	private float _startOil;

	private bool _used;

	private void Awake()
	{
		if (!Preloader.ShopConfig.DrillingDrone)
		{
			base.gameObject.SetActive(value: false);
		}
	}

	private void Update()
	{
		Root.SetActive(_available && !_used && !DroneManager.Instance.IsDrilling() && SingletonMB<GameManager>.Instance.currentOilUI.OilValue > 30f && SingletonMB<GameManager>.Instance.currentOilUI.OilValue < _startOil - 5f);
	}

	public void OnClick()
	{
		if (SingletonMB<GameManager>.Instance.BetterNoAds)
		{
			OnRVDone(success: true);
		}
		else
		{
			OnRVDone(success: true);
		}
	}

	public void OnRVDone(bool success)
	{
		if (success)
		{
			_used = true;
			DroneManager.Instance.OnRVTaken();
		}
	}

	private void OnEnable()
	{
		if ((bool)SingletonMB<DuelModeManager>.Instance)
		{
			base.gameObject.SetActive(value: false);
			return;
		}
		_available = !SingletonMB<OnboardingManager>.Instance.IsOnboardingActive && SingletonMB<GameManager>.Instance.ReturnCount >= 2;
		_startOil = SingletonMB<GameManager>.Instance.currentOilUI.OilValue;
		_used = false;
		Text.text = ((InventoryManager.Instance.GetInventoryCount(DroneItem) > 0) ? "Refill Drone!" : "Free Drone!");
	}
}
